package com.heatingcharge.controller.sys;


import com.heatingcharge.common.json.JsonData;
import com.heatingcharge.common.util.R;
import com.heatingcharge.dto.MenuLevelDTO;
import com.heatingcharge.service.sys.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author devin.jiang
 * @since 2019-06-26
 */
@RestController
@RequestMapping("/sys-menu")
public class SysMenuController {
    @Autowired
    ISysMenuService sysMenuService;

    @GetMapping()
    public R getMenus(){
        List<MenuLevelDTO> menuLevelDTOS=sysMenuService.getMenus();
        return R.ok(menuLevelDTOS);
    }

    @GetMapping("{roleId}/menuIds")
    public R getMenuIdsByRoleId(@PathVariable("roleId") Integer roleId){
        List<Integer> menuIdsByRoleId = sysMenuService.getMenuIdsByRoleId(roleId);
        return R.ok(menuIdsByRoleId);
    }

    @PostMapping("/role/{roleId}")
    public R saveRoleMenus(@PathVariable("roleId") Integer roleId,@RequestBody List<Integer> menuIds){
        Integer result= sysMenuService.saveRoleMenus(roleId,menuIds);
        return R.ok();
    }
}

